﻿using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;
using EasyXaf.EntityDesigner.BusinessObjects;

namespace EasyXaf.EntityDesigner.BusinessObjects.Enums;

/// <summary>
/// 枚举
/// </summary>
[XafDisplayName("枚举")]
[XafDefaultProperty(nameof(DisplayName))]
public partial class Enumeration : BaseObject
{
	private string _name;
	private string _namespace;
	private string _caption;
	private string _description;
	private DomainModel _domainModel;

	/// <summary>
	/// 名称
	/// </summary>
	[XafDisplayName("名称")]
	[RuleRequiredField]
	public string Name
	{
		get => _name;
		set => SetPropertyValue(nameof(Name), ref _name, value);
	}

	/// <summary>
	/// 显示名称
	/// </summary>
	[XafDisplayName("显示名称")]
	public string DisplayName
	{
		get => GetDisplayName();
	}

	/// <summary>
	/// 命名空间
	/// </summary>
	[XafDisplayName("命名空间")]
	[EditorAlias("LookupStringPropertyEditor")]
	public string Namespace
	{
		get => _namespace;
		set => SetPropertyValue(nameof(Namespace), ref _namespace, value);
	}

	/// <summary>
	/// 标题
	/// </summary>
	[XafDisplayName("标题")]
	public string Caption
	{
		get => _caption;
		set => SetPropertyValue(nameof(Caption), ref _caption, value);
	}

	/// <summary>
	/// 描述
	/// </summary>
	[XafDisplayName("描述")]
	[Size(SizeAttribute.Unlimited)]
	public string Description
	{
		get => _description;
		set => SetPropertyValue(nameof(Description), ref _description, value);
	}

	/// <summary>
	/// 领域模型
	/// </summary>
	[XafDisplayName("领域模型")]
	[Association("Enums-DomainModel")]
	public DomainModel DomainModel
	{
		get => _domainModel;
		set => SetPropertyValue(nameof(DomainModel), ref _domainModel, value);
	}

	/// <summary>
	/// 枚举值
	/// </summary>
	[XafDisplayName("枚举值")]
	[Association("Values-Enum")]
	[DevExpress.Xpo.Aggregated]
	public XPCollection<EnumValue> Values
	{
		get => GetCollection<EnumValue>(nameof(Values));
	}

	public Enumeration(Session session)
		: base(session)
	{
	}

	private partial string GetDisplayName();
}
